package com.zy.is.common.utils;


import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * 加密工具类
 * @author Yanzy
 */
@Slf4j
public class SignUtil {

    /**
     * 加密方式
     */
    public static final String MD5 = "MD5";
    /**
     * 加密迭代数
     */
    public static final int SIGN_TIMES = 10;


    /**
     * shiro MD5加密
     * @param credentials 待加密值
     * @param salt 加密盐
     * @return 加密值
     */
    public static String shiroMd5(Object credentials, Object salt) throws Exception {
        ByteSource credentialsSalt = ByteSource.Util.bytes(salt);;
        SimpleHash simpleHash = new SimpleHash(MD5, credentials, credentialsSalt, SIGN_TIMES);
        log.debug("shiro md5加密值: {}", simpleHash);
        return simpleHash.toString();
    }

    public static void main(String[] args) {

        try {
            System.out.println(shiroMd5("sysadmin", "sysadmin"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
